﻿using System;
using System.Collections.Generic;
using System.Text;
using MySql.Data.MySqlClient;
using System.Collections;
using BBMS.DLL.Base;
namespace BBMS.DLL.DataContract
{
    public class NhanVienList : BBMS.DLL.Base.ObjectList
    {
        public override void LoadData()
        {
            NhanVien nv = new NhanVien();
            if (hash == null) hash = new System.Collections.Hashtable();
            hash.Clear();
            try
            {
                MySqlConnection con = new MySqlConnection(Base.Config.ConnectionString());
                con.Open();
                MySqlCommand cmd = con.CreateCommand();
                cmd.CommandText = "select * from " + nv.TableName;
                MySqlDataReader rd = cmd.ExecuteReader();

                while (rd.Read())
                    this.Add(nv.DataReaderToObject(rd));

                rd.Close();
                rd.Dispose();
                con.Close();
                con.Dispose();
            }
            catch
            {
                this.hash.Clear();
            }
        }

        public static System.Collections.ArrayList getAllUserName()
        {
            NhanVien nv = new NhanVien();
            ArrayList arrRet = new ArrayList();
            try
            {
                MySqlConnection con = new MySqlConnection(Base.Config.ConnectionString());
                con.Open();
                MySqlCommand cmd = con.CreateCommand();
                cmd.CommandText = "select ID, UserName, FullName, Mobile, Department, Position from " + nv.TableName;
                MySqlDataReader rd = cmd.ExecuteReader();

                while (rd.Read())
               //     arrRet.Add(new KeyValuePair(Convert.ToInt32(rd["ID"].ToString()), rd["UserName"].ToString()));
                    arrRet.Add(new KeyValuePair(new NhanVien(Convert.ToInt32(rd["ID"].ToString()), rd["UserName"].ToString()
                        , rd["FullName"].ToString(), rd["Mobile"].ToString()
                        , rd["Department"].ToString(), rd["Position"].ToString()), rd["UserName"].ToString()));
                   // this.Add(nv.DataReaderToObject(rd));

                rd.Close();
                rd.Dispose();
                con.Close();
                con.Dispose();
            }
            catch
            {
               
            }
            
            return arrRet;
        }



    }
}
